package com.dyz.leetcode;

public class CountSubstrings647 {
    //解题方法 中心扩散法则
    int res = 0;
    char [] letters;
    public int countSubstrings(String s) {
        letters = s.toCharArray();
        for (int i=0; i<letters.length; i++){
            centraldiffusion(i, i);//奇数个，中心一个点
            centraldiffusion(i,i+1);//偶数个
        }
        return res;

    }
    private void centraldiffusion(int start,int end){
        while (start>=0 && end<letters.length && letters[start]==letters[end]){
            res++;
            start--;
            end++;
        }
    }
}
